package com.boot.service;

import com.boot.mapper.UserMapper;
import com.boot.pojo.CustomUserDetail;
import com.boot.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

@Service
public class CustomUserDetailsService implements UserDetailsService {
    @Autowired
    private UserService userService;
    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        CustomUserDetail customUserDetail = userService.selectUserDetailByUsername(username);
        if (customUserDetail == null) {
            throw new UsernameNotFoundException(username);
        }
        return customUserDetail;
    }
}
